package org.oc.qaq.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.oc.qaq.annotation.Autofill;
import org.oc.qaq.entity.FileEntity;
import org.oc.qaq.enumeration.OperationType;
import org.oc.qaq.vo.FileVO;

import java.util.List;

@Mapper
public interface FileMapper {

    @Autofill(OperationType.INSERT)
    void insert(FileEntity fileEntity);

    @Select("select * from file where name=#{fileName}")
    FileEntity selectFileByName(String fileName);

    @Delete("delete from file where id=#{id}")
    void deleteById(String id);

    @Select("select * from file where id=#{fileId}")
    FileEntity selectFileById(String fileId);

    @Autofill(OperationType.UPDATE)
    void update(FileEntity file);

    Page<FileVO> selectFilesByUserIdAndTags(
            String keyword,
            String userId,
            List<String> tags,
            List<Long> roleIds,
            @Param("deleted") boolean isRecycleQuery);

    void insertFileTags(String fileId, List<Long> tagIds);

    void deleteFileTags(String id);

    Page<FileVO> selectAllFiles(String keyword, @Param("deleted") boolean isRecycleQuery);

    @Insert("insert into file_tag(file_id,tag_id) values(#{fileId},#{tagId})")
    void insertFileTag(String fileId, Long tagId);
}
